﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CustomsSystem.DAL;
using CustomsSystem.Model;
using System.Data;

namespace CustomsSystem.BLL
{
    public class SheetInfoManage
    {
        public SheetInfoService dal = new SheetInfoService();

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId("sheetID");
        }
        public bool Exists(int sheetID)
        {
            return dal.Exists(sheetID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetMainInfo(string strWhere)
        {
            return dal.GetMainInfo(strWhere);
        }
        /// <summary>
        /// 获取多表数据的视图
        /// </summary>
        /// <returns></returns>
        public DataSet GetView(string strWhere)
        {
            return dal.GetView(strWhere);
        }

        /// <summary>
        /// 获取用于统计委托单数据视图
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetViewByCalc(string strWhere)
        {
            return dal.GetViewByCalc(strWhere);
        }
        /// <summary>
        /// 获取多表数据的视图
        /// </summary>
        /// <returns></returns>
        public DataSet GetViewOfUnaudit(string strWhere)
        {
            return dal.GetViewOfUnaudit(strWhere);
        }
        /// <summary>
        /// 获取多表数据的视图
        /// </summary>
        /// <returns></returns>
        public DataSet GetViewOfAudit(string strWhere)
        {
            return dal.GetViewOfAudit (strWhere);
        }
        /// <summary>
        /// 启动工作流所需数据
        /// </summary>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public DataSet GetWorkFlowStart(string strwhere)
        {
            return dal.GetWorkflowStart(strwhere);
        }
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CustomsSystem.Model.sheetInfo GetModel(int sheetID)
		{
			return dal.GetModel(sheetID);
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<CustomsSystem.Model.sheetInfo> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<CustomsSystem.Model.sheetInfo> DataTableToList(DataTable dt)
		{
			List<CustomsSystem.Model.sheetInfo> modelList = new List<CustomsSystem.Model.sheetInfo>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				CustomsSystem.Model.sheetInfo model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CustomsSystem.Model.sheetInfo model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CustomsSystem.Model.sheetInfo model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 在销账页面把“挂账单位”录进委托单表
        /// </summary>
        public void AddGuaZhangDW(int sheetID, string guaZhangDW)
        {
            dal.AddGuaZhangDW(sheetID, guaZhangDW);
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            return dal.Delete(ID);
        }

		
    }
}
